import fun

Allotment = ""

url = "http://www.xs52.la/xiaoshuo/1/1096/"
content = ""

content = fun.gethtml("http://www.xs52.la/xiaoshuo/1/1096/2804794.html")
# print(content)
nextUrl = fun.Getnext(content)
# print(content)
title = fun.GetTitle(content)
# 处理一下多余的东西
content = fun.mreplace(content)
if title is not None:
    content = "   " + title + "\n\n" + content
# print(content)
print(title)

Allotment = content

while nextUrl is not None:
    try:
        content = fun.gethtml(url + nextUrl)
        # 获取下一页
        nextUrl = fun.Getnext(content)
        # 获取标题
        title = fun.GetTitle(content)
        # 使文本更美观
        content = fun.mreplace(content)
        if title is not None:
            content = "   " + title + "\n\n" + content
        Allotment += "\n========\n" + content

        if title is None or nextUrl is None:
            continue
        print(title + " === " + nextUrl)
    except BaseException:
        break
TextFile = open("全职法师.txt", "wb")
TextFile.write(Allotment.encode(encoding="utf-8"))
TextFile.close()

print("运行结束")
